package com.bdqn.zhao.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bdqn.zhao.pojo.CiApplyfor;
import com.bdqn.zhao.service.CiApplyforService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 楼层表 前端控制器
 * </p>
 *
 * @author zhangsan
 * @since 2023-04-24
 */
@Controller
@RequestMapping("/ciApplyfor")
public class CiApplyforController {
    @Resource
    CiApplyforService applyforService;

    @GetMapping("/selectApplyfor")
    @ResponseBody
    public String mohu(String name, String phone, HttpServletRequest request){
        QueryWrapper<CiApplyfor> queryWrapper = new QueryWrapper<>();
        if (name!=null){
            queryWrapper.like("name",name);
        }
        if (phone!=null){
            queryWrapper.like("phone",phone);
        }
        List<CiApplyfor> ciApplyforList = applyforService.list(queryWrapper);
        if (ciApplyforList!=null){
            System.out.println(1);
            return "1";
        }
        request.setAttribute("ciApplyforList",ciApplyforList);
        return "";
    }

    @PostMapping("updateApplyfor")
    @ResponseBody
    public String updateZt( Integer id, String status){
        CiApplyfor applyfor = applyforService.getById(id);
        applyfor.setStatus(status);
        if (applyforService.updateById(applyfor)){
            System.out.println("成功");
        }else {
            System.out.println("失败");
        }

        return "";

    }
    @PostMapping("delApplyfor")
    @ResponseBody
    public String del(Integer id){
        if(applyforService.removeById(id)){
            System.out.println("成功");
        }else {
            System.out.println("失败");
        }
        return "";
    }

}

